import { GET, POST } from './request'
import type { PageReq, PageRes } from './types'

// 单个设备实体
export interface DeviceItem {
  id: number
  name: string
  type: 'camera' | 'sensor' | 'gateway'
  status: 0 | 1          // 0 离线 1 在线
  createdAt: string
}

/* 1. 创建设备 ---------------------------------------------------- */
export interface CreateDeviceBody {
  characteristic: string
  device_type_id: number
  is_group: number
  name: string
  parent_device_id: number
  x:number
  y:number
  z:number
}
export const createDevice = (data: CreateDeviceBody) =>
  POST<DeviceItem>('/v1/devices/', data)

/* 2. 分页查询设备 ------------------------------------------------- */
export interface DeviceListReq extends PageReq {
  name?: string          // 模糊搜索
  type?: DeviceItem['type']
}
export const getDevicePage = (params: DeviceListReq) =>
  GET<PageRes<DeviceItem>>('/v1/devices/?x_start=1&x_end=20', params)